﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - ProductWebSite</title>

    <environment include="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
        <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
    </environment>

    <script src="//cdn.bootcss.com/oidc-client/1.4.1/oidc-client.min.js"></script>
</head>
<body>
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">ProductWebSite</a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
                    <li><a asp-area="" asp-controller="Home" asp-action="About">About</a></li>
                    <li><a asp-area="" asp-controller="Home" asp-action="Contact">Contact</a></li>
                </ul>
            </div>
            <div class="navbar-right">
                <ul class="nav navbar-nav">
                    <li><button type="button" id="login" >登录</button></li>
                    <li><button type="button" id="logout" >注销</button></li>
                    <li><button type="button" id="api" >Use Access Token Call API</button></li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <div id="results"></div>
        <div id="error"></div>
        <footer>
            <p>&copy; 2017 - ProductWebSite</p>
        </footer>
    </div>

    

    <environment include="Development">
        <script src="~/lib/jquery/dist/jquery.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    </environment>
    <environment exclude="Development">
        <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"
                asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"
                integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                crossorigin="anonymous"
                integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
        </script>
        <script src="~/js/site.min.js" asp-append-version="true"></script>
    </environment>


    <script type="text/javascript">

        function display(selector, data) {
            if (data && typeof data === 'string') {
                data = JSON.parse(data);
            }
            if (data) {
                data = JSON.stringify(data, null, 2);
            }

            $(selector).text(data);
        }

        var config = {
            authority: "http://localhost:5000",
            client_id: "js.implicit",
            redirect_uri: "http://localhost:5002/oidc/login-callback.html",
            post_logout_redirect_uri: "http://localhost:5002/",
            silent_redirect_uri: "http://localhost:5002/oidc/refresh-token.html",
            automaticSilentRenew: true,

            accessTokenExpiringNotificationTime:4,
            response_type: "id_token token",
            scope: "openid profile productservice",

            filterProtocolClaims: true
        };
        var mgr = new Oidc.UserManager(config);

        Oidc.Log.logger = console;

        mgr.events.addUserLoaded(function (loadedUser) {
            display("#results", loadedUser);
        });

        //mgr.getUser().then(function (user) {
        //    if (user) {
        //        log("User client id in ", user.id_token);
        //        log("User profile in ", user.profile);
        //        log("User session state in", user.session_state);
        //        log("User access_token in", user.access_token);
        //        log("User refresh_token in", user.refresh_token);
        //        log("User scope in", user.scope);
        //        log("User expires_at in", user.expires_at);
        //        log("User expires_in in", user.expires_in);
        //        log("User expired in", user.expired);
        //        log("User scopes in", user.scopes);
        //        display("#results", user);
        //    }
        //    else {
        //        display("#results","User not logged in");
        //    }
        //});


        $('#login').on('click', function () {
            mgr.signinRedirect();
        });

        $('#logout').on('click', function () {
            mgr.signoutRedirect();
        });


        $('#api').on('click', function () {
            mgr.getUser().then(function (user) {
                $.ajax({
                    cache: false,
                    url: "http://localhost:5001/api/values",
                    headers: {
                        Authorization: "Bearer " + user.access_token
                    },
                    dataType: "json",
                    success: show,
                    error: show,
                });

            });
        });

        function show(data) {
            if (data && typeof data === 'string') {
                data = JSON.parse(data);
            }
            if (data) {
                data = JSON.stringify(data, null, 2);
            }
            $("#error").text(data);
        }

    </script>



    @RenderSection("Scripts", required: false)


   


</body>
</html>
